package com.asnop;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ecbt.rest.util.ExcelHelper;

public class CheckMarkno {

	public static void main(String[] args) {
		Integer[] markno = { 4054,4047};

		Integer[][] ranges = {
				{	2711	,	2711	},
				{	1548	,	1548	}
		};
		
		markno = readMarkNo("D:\\AijunTao\\Desktop\\问题运单\\车辆清单.xls");
		ranges = readMarkNoRanges("D:\\AijunTao\\Desktop\\问题运单\\汇总唛头号.xls");
//		for(Integer mark : markno) {
//			for(Integer[] rag : ranges) {
//				if (mark >= rag[0] && mark <= rag[1]) {
//					System.out.println(mark);
//				}
//			}
//		}
		// 从车辆清单中 找到 未报交的车辆 唛头号
		Map<Integer, Integer> map = new HashMap<>();
		// 车辆清单中
		for(Integer[] rag : ranges) {
			for(int mk = rag[0]; mk <= rag[1]; mk++) {
				map.put(mk, mk);
			}
		}
		for(Integer extMk : markno) {
			if(map.containsKey(extMk)) {
				map.remove(extMk);
			}
		}
		for(Integer mk : map.keySet()) {
			System.out.println(mk);
		}
	}

	private static Integer[] readMarkNo(String path) {
		List<List> resultList = readExcel(path);
		 Integer[] realut = new Integer[resultList.size() - 1];
		for(int i = 1;i < resultList.size();i++){
			List one = (List)resultList.get(i);
			String markNo = formatColumData(one.get(9));
			if (markNo != null) {
				realut[i-1] = Integer.parseInt(markNo);
			}
		}
		return realut;
	}
	
	public static String formatColumData(Object object) {
		if(object != null)
			return object.toString();
		return null;
	}
	
	private static Integer[][] readMarkNoRanges(String path) {
		List<List> resultList = readExcel(path);
		 Integer[][] realut = new Integer[resultList.size() - 1][2];
		for(int i = 1;i < resultList.size();i++){
			List one = (List)resultList.get(i);
			String markNo = formatColumData(one.get(7));
			String markNoE = formatColumData(one.get(8));
			if (markNo != null) {
				realut[i-1][0] = Integer.parseInt(markNo);
				realut[i-1][1] = Integer.parseInt(markNoE);
			}
		}
		return realut;
	}
	
	public static List<List> readExcel(String path){
		File newFile = new File(path);
		List<List> resultList = new ArrayList<List>();
		try {
			resultList = ExcelHelper.readExcel2List(newFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultList;
	}
}
